
cc.Class({
    extends: cc.Component,

    properties: {
    },

    // LIFE-CYCLE CALLBACKS:

    // onLoad () {},

    start () {
        this.schedule(this.updateOne,1);

        this.label = this.node.getComponent(cc.Label);
        // this.runing = false
        // this.startRevese(Date.now() + 10000,function(){
        //     cc.log('倒计时完成')
        // })
    },

    startRevese(time,cb){
        this.runing = true;
        this.targetTime = time
        this.cb = cb;
    },

    updateOne (dt) {
        if(!this.runing){
            return;
        }
        this.targetTime = Math.ceil(this.targetTime-dt);
        var dtime = this.targetTime
        if(dtime <= 0){
            this.runing = false;
            this.cb && this.cb();
            // return;
        }
        var min = Math.floor(dtime / 60);
        var sec = Math.floor(dtime % 60);
        min = min < 10 ? '0'+min : min;
        sec = sec < 10 ? '0'+sec : sec;
        this.label.string = min+':'+sec

        // var dtime = (this.targetTime - Date.now())/1000;
        // if(dtime <= 0){
        //     this.runing = false;
        //     this.cb && this.cb();
        //     return;
        // }
        // var min = Math.floor(dtime / 60);
        // var sec = Math.floor(dtime % 60);
        // min = min < 10 ? '0'+min : min;
        // sec = sec < 10 ? '0'+sec : sec;
        // this.label.string = min+':'+sec
    },
});
